package android.graphics;

import android.util.Log;

import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class FinalxLog {

    //config ++
    static final String MY_LOG_PROCS[] = {"com.sonyericsson.album", "com.android.gallery3d"};


    static FileInputStream fis = null;
    static BufferedReader br = null;
    static String strCmdline = null;

    public static void d(final String msg) {

        try {
            if ( null == fis ) {
                fis = new FileInputStream("/proc/self/cmdline");
            }

            if ( null == br) {
                br = new BufferedReader(new InputStreamReader(fis));
            }

            if (null == strCmdline) {
                strCmdline = br.readLine().replace("\0", "");
                //Log.d("FinalxLog.log", "strCmdline: " + strCmdline);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        boolean isSelf = false;
        for (String proc : MY_LOG_PROCS ) {
            if (proc.equals(strCmdline)) {
                isSelf = true;
                break;
            }
        }

        if (isSelf) {

            final Throwable t = new Throwable();
            final StackTraceElement[] elements = t.getStackTrace();

            final String callerClassName = elements[1].getFileName();
            final String callerMethodName = elements[1].getMethodName();

            long threadId = Thread.currentThread().getId();

            String TAG = "[" + callerClassName + " " + Thread.currentThread().getId() + "]";

            Log.d(TAG, "[" + callerMethodName + "] " + msg);
        }
    }
}
